package com.insurance.config.shiro;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;

/**
 * shiro自定义realm
 * @version 1.0
 * @date 2021/2/22
 **/
public class UserRealm extends AuthorizingRealm {

    /**
     * 授权
     * @param principalCollection
     * @return
     */
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }

    /**
     * 认证
     * @param authenticationToken
     * @return
     * @throws AuthenticationException
     */
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {

        String userName = (String) authenticationToken.getPrincipal();

//        SysUser sysUser = sysUserService.findByUserName(userName);

        /*if(sysUser == null){
            return null;
        }*/
        //密码加密计算用于查看
//        SimpleHash result = new SimpleHash("MD5", "123456", ByteSource.Util.bytes("admin".getBytes()), 1);


        /*SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(
                new LoginUser(sysUser), sysUser.getPassword(), ByteSource.Util.bytes(userName), "userRealm");
        return simpleAuthenticationInfo;*/

        return null;
    }
}
